Ext.namespace('Divo');
Ext.namespace('Divo.app');

Divo.app.StockInForm = Ext.extend(Divo.Base.EditForm, {
  fields : new Ext.util.MixedCollection(),
  dataRecordMeta : Ext.data.Record.create([{
        name : "_p_record_status",
        type : "string"
      }, {
        name : "id",
        type : "float"
      }, {
        name : "stockId",
        type : "float"
      }, {
        name : "stockName",
        type : "string"
      }, {
        name : "number",
        type : "string"
      }, {
        name : "accountTime",
        type : "string"
      }, {
        name : "actionTypeId",
        type : "float"
      }, {
        name : "actionName",
        type : "string"
      }, {
        name : "inTime",
        type : "string"
      }, {
        name : "accountId",
        type : "float"
      }, {
        name : "accountName",
        type : "string"
      }, {
        name : "invoice",
        type : "string"
      }, {
        name : "invoiceTime",
        type : "string"
      }, {
        name : "supplierId",
        type : "float"
      }, {
        name : "supplierName",
        type : "string"
      }, {
        name : "purchaseId",
        type : "float"
      }, {
        name : "purchaseName",
        type : "string"
      }, {
        name : "checkId",
        type : "float"
      }, {
        name : "checkName",
        type : "string"
      }, {
        name : "money",
        type : "float"
      }, {
        name : "note",
        type : "string"
      }]),
  initComponent : function() {
    var me = this;
    var tn = 1;

    this.fields.add("_p_record_status", new Ext.form.Hidden({
              name : "_p_record_status"
            }));
    this.fields.add("id", new Ext.form.Hidden({
              name : "id",
              dataIndex : "id",
              insert_allowed : true,
              update_allowed : true
            }));
    this.fields.add("stockId", new Ext.form.Hidden({
              name : "stockId",
              dataIndex : "stockId",
              insert_allowed : true,
              update_allowed : true
            }));
    this.fields.add("actionTypeId", new Ext.form.Hidden({
              name : "actionTypeId",
              dataIndex : "actionTypeId",
              insert_allowed : true,
              update_allowed : true
            }));
    this.fields.add("accountId", new Ext.form.Hidden({
              name : "accountId",
              dataIndex : "accountId",
              insert_allowed : true,
              update_allowed : true
            }));
    this.fields.add("supplierId", new Ext.form.Hidden({
              name : "supplierId",
              dataIndex : "supplierId",
              insert_allowed : true,
              update_allowed : true
            }));
    this.fields.add("purchaseId", new Ext.form.Hidden({
              name : "purchaseId",
              dataIndex : "purchaseId",
              insert_allowed : true,
              update_allowed : true
            }));
    this.fields.add("checkId", new Ext.form.Hidden({
              name : "checkId",
              dataIndex : "checkId",
              insert_allowed : true,
              update_allowed : true
            }));

    this.fields.add("stockName", new app.base.ComboBox({
              fieldLabel : '仓库',
              name : 'stockName',
              tabIndex : tn++,
              store : Divo.com.Lib.getStockDs(),
              displayField : 'name',
              dataIndex : 'stockName',
              mode : 'remote',
              typeAhead : false,
              forceSelection : true,
              loadingText : '正在搜索...',
              listWidth : 100,
              labelSeparator : ":*",
              width : 100,
              minChars : 0,
              allowBlank : false,
              insert_allowed : true,
              update_allowed : true,
              onSelect : function(record) {
                var data = record.data;
                me.setFieldValue("stockName", data.name);
                me.setFieldValue("stockId", data.id);
                this.onTriggerClick();
              }
            }));
    this.fields.add("accountTime", new app.base.DateField({
              name : "accountTime",
              dataIndex : "accountTime",
              format : 'Y.m',
              fieldLabel : "核算年月",
              allowBlank : false,
              labelSeparator : ":*",
              tabIndex : tn++,
              width : 100,
              editable : true,
              insert_allowed : true,
              update_allowed : true
            }));
    this.fields.add("actionName", new app.base.ComboBox({
              fieldLabel : '入库类型',
              name : 'actionName',
              tabIndex : tn++,
              store : Divo.com.Lib.getActionTypeDs(),
              displayField : 'name',
              dataIndex : 'actionName',
              mode : 'remote',
              typeAhead : false,
              forceSelection : true,
              loadingText : '正在搜索...',
              listWidth : 100,
              labelSeparator : ":*",
              width : 100,
              minChars : 0,
              allowBlank : false,
              insert_allowed : true,
              update_allowed : true,
              onSelect : function(record) {
                var data = record.data;
                me.setFieldValue("actionName", data.name);
                me.setFieldValue("actionTypeId", data.id);
                this.onTriggerClick();
              }
            }));
    this.fields.add("inTime", new app.base.DateField({
              name : "inTime",
              dataIndex : "inTime",
              format : 'Y.m.d',
              fieldLabel : "入库时间",
              allowBlank : false,
              labelSeparator : ":*",
              tabIndex : tn++,
              width : 100,
              editable : true,
              insert_allowed : true,
              update_allowed : true
            }));
    this.fields.add("accountName", new app.base.ComboBox({
              fieldLabel : '结算方式',
              name : 'accountName',
              tabIndex : tn++,
              store : Divo.com.Lib.getAccountTypeDs(),
              displayField : 'name',
              dataIndex : 'accountName',
              mode : 'remote',
              typeAhead : false,
              forceSelection : true,
              loadingText : '正在搜索...',
              listWidth : 300,
              labelSeparator : ":*",
              width : 100,
              minChars : 0,
              allowBlank : false,
              insert_allowed : true,
              update_allowed : true,
              onSelect : function(record) {
                var data = record.data;
                me.setFieldValue("accountName", data.name);
                me.setFieldValue("accountId", data.id);
                this.onTriggerClick();
              }
            }));
    this.fields.add("invoice", new app.base.TextField({
              name : "invoice",
              dataIndex : "invoice",
              fieldLabel : "发票号",
              allowBlank : false,
              labelSeparator : ":*",
              tabIndex : tn++,
              width : 100,
              insert_allowed : true,
              update_allowed : true
            }));
    this.fields.add("invoiceTime", new app.base.DateField({
              name : "invoiceTime",
              dataIndex : "invoiceTime",
              format : 'Y.m.d',
              fieldLabel : "发票时间",
              allowBlank : false,
              labelSeparator : ":*",
              tabIndex : tn++,
              width : 100,
              editable : true,
              insert_allowed : true,
              update_allowed : true
            }));
    this.fields.add("supplierName", new app.base.ComboBox({
              fieldLabel : '供应商',
              name : 'supplierName',
              tabIndex : tn++,
              store : Divo.com.Lib.getSupplierEnableDs(),
              displayField : 'name',
              dataIndex : 'supplierName',
              mode : 'remote',
              typeAhead : false,
              forceSelection : true,
              loadingText : '正在搜索...',
              listWidth : 300,
              labelSeparator : ":*",
              width : 100,
              minChars : 0,
              allowBlank : false,
              insert_allowed : true,
              update_allowed : true,
              onSelect : function(record) {
                var data = record.data;
                me.setFieldValue("supplierName", data.name);
                me.setFieldValue("supplierId", data.id);
                this.onTriggerClick();
              }
            }));
    this.fields.add("purchaseName", new app.base.ComboBox({
              fieldLabel : '采购人',
              name : 'purchaseName',
              tabIndex : tn++,
              store : Divo.com.Lib.getUsersDs(),
              displayField : 'name',
              dataIndex : 'purchaseName',
              mode : 'remote',
              typeAhead : false,
              forceSelection : true,
              loadingText : '正在搜索...',
              listWidth : 300,
              labelSeparator : ":*",
              width : 100,
              minChars : 0,
              allowBlank : false,
              insert_allowed : true,
              update_allowed : true,
              onSelect : function(record) {
                var data = record.data;
                me.setFieldValue("purchaseName", data.name);
                me.setFieldValue("purchaseId", data.id);
                this.onTriggerClick();
              }
            }));
    this.fields.add("checkName", new app.base.ComboBox({
              fieldLabel : '验收人',
              name : 'checkName',
              tabIndex : tn++,
              store : Divo.com.Lib.getUsersDs(),
              displayField : 'name',
              dataIndex : 'checkName',
              mode : 'remote',
              typeAhead : false,
              forceSelection : true,
              loadingText : '正在搜索...',
              listWidth : 300,
              labelSeparator : ":*",
              width : 100,
              minChars : 0,
              allowBlank : false,
              insert_allowed : true,
              update_allowed : true,
              onSelect : function(record) {
                var data = record.data;
                me.setFieldValue("checkName", data.name);
                me.setFieldValue("checkId", data.id);
                this.onTriggerClick();
              }
            }));
    this.fields.add("money", new Ext.form.Label({
              name : "money",
              dataIndex : "money",
              fieldLabel : "总金额",
              tabIndex : tn++,
              width : 100,
              insert_allowed : true,
              update_allowed : true
            }));
    this.fields.add("note", new app.base.TextArea({
              name : "note",
              dataIndex : "note",
              fieldLabel : "备注",
              allowBlank : false,
              labelSeparator : ":*",
              tabIndex : tn++,
              width : 400,
              insert_allowed : true,
              update_allowed : true
            }));
    Ext.apply(this, {
      items : [this.fields.get("_p_record_status"), this.fields.get("id"),
          this.fields.get("stockId"), this.fields.get("actionTypeId"),
          this.fields.get("accountId"), this.fields.get("supplierId"),
          this.fields.get("purchaseId"), this.fields.get("checkId"), {
            layout : "form",
            columnWidth : 1,
            labelAlign : "right",
            labelWidth : 100,
            width : 700,
            items : [{
              layout : 'fit',
              region : 'north',
              border : false,
              items : [{
                layout : "column",
                bodyStyle : 'padding:0 0 ;',
                border : false,
                items : [{
                  layout : "form",
                  columnWidth : .3,
                  labelAlign : 100,
                  items : [this.fields.get("stockName"),
                      this.fields.get("actionName"),
                      this.fields.get("invoice"),
                      this.fields.get("purchaseName")]
                }, {
                  layout : "form",
                  columnWidth : .3,
                  labelAlign : 100,
                  items : [this.fields.get("accountTime"),
                      this.fields.get("inTime"),
                      this.fields.get("invoiceTime"),
                      this.fields.get("checkName")]
                }, {
                  layout : "form",
                  columnWidth : .4,
                  labelAlign : 100,
                  items : [this.fields.get("accountName"),
                      this.fields.get("supplierName"), this.fields.get("money")]
                }]
              }],
              height : 105,
              width : 700
            }, this.fields.get("note")]
          }],
      border : false,
      frame : true,
      firstFocusFieldName : "stockName"
    });
    Divo.app.StockInForm.superclass.initComponent.apply(this, arguments);
  },
  onRender : function() {
    Divo.app.StockInForm.superclass.onRender.apply(this, arguments);
  },
  newDataRecord : function() {
    return new this.dataRecordMeta({
          _p_record_status : "insert",
          id : "",
          name : "",
          state : ""
        });
  }

});
Ext.reg("Divo.app.StockInForm", Divo.app.StockInForm);